/**
  ******************************************************************************
  * @file    sync_method.h
  * @author  ashuai0110
  * @version V2.3
  * @date    2024-07-01
  * @brief   伪线程同步方法(信号量,互斥锁,事件集)
  *
  ******************************************************************************
  * @attention
  *
  * 版权声明:内容为编者(ashuai0110)原创,使用请注明出处,当然,你也可以不这样做^_^
  * 出处链接:https://gitee.com/ashuai0110/mcu_reuse_development_module.git
  *
  ******************************************************************************
  */

#ifndef __MULTISYNC_H
#define __MULTISYNC_H

#ifdef __cplusplus
extern "C" {
#endif

/* 包含头文件-----------------------------------------------------------------*/
#include "common_include.h"

/**
 * @addtogroup modules
 * @{
 */

/**
 * @addtogroup sync_method
 * @{
 */

/* 宏定义---------------------------------------------------------------------*/
/**
 * @defgroup sync_method_global_macros sync method global macros
 * @{
 */

/**
 * @defgroup sync_mutex_flg sync mutex flag
 * @{
 */
#define MUTEX_UNLOCK                    (0u) /*!< 互斥锁-未上锁 */
#define MUTEX_LOCK                      (1u) /*!< 互斥锁-上锁 */
/**
 * @}
 */

/**
 * @defgroup sync_event_flg sync event flag
 * @{
 */
#define EVENT_OR                        (0u) /*!< 事件集-或 */
#define EVENT_AND                       (1u) /*!< 事件集-与 */
/**
 * @}
 */

/**
 * @defgroup sync_event_act sync event action
 * @{
 */
#define EVENT_CLEAR                     (0u) /*!< 事件集-清除 */
#define EVENT_HOLD                      (1u) /*!< 事件集-保持 */
/**
 * @}
 */

/**
 * @defgroup sync_event_bit sync event bit
 * @{
 */
#define EVENT_BIT0                      (0x1ul<<0)
#define EVENT_BIT1                      (0x1ul<<1)
#define EVENT_BIT2                      (0x1ul<<2)
#define EVENT_BIT3                      (0x1ul<<3)
#define EVENT_BIT4                      (0x1ul<<4)
#define EVENT_BIT5                      (0x1ul<<5)
#define EVENT_BIT6                      (0x1ul<<6)
#define EVENT_BIT7                      (0x1ul<<7)
#define EVENT_BIT8                      (0x1ul<<8)
#define EVENT_BIT9                      (0x1ul<<9)
#define EVENT_BIT10                     (0x1ul<<10)
#define EVENT_BIT11                     (0x1ul<<11)
#define EVENT_BIT12                     (0x1ul<<12)
#define EVENT_BIT13                     (0x1ul<<13)
#define EVENT_BIT14                     (0x1ul<<14)
#define EVENT_BIT15                     (0x1ul<<15)
#define EVENT_BIT16                     (0x1ul<<16)
#define EVENT_BIT17                     (0x1ul<<17)
#define EVENT_BIT18                     (0x1ul<<18)
#define EVENT_BIT19                     (0x1ul<<19)
#define EVENT_BIT20                     (0x1ul<<20)
#define EVENT_BIT21                     (0x1ul<<21)
#define EVENT_BIT22                     (0x1ul<<22)
#define EVENT_BIT23                     (0x1ul<<23)
#define EVENT_BIT24                     (0x1ul<<24)
#define EVENT_BIT25                     (0x1ul<<25)
#define EVENT_BIT26                     (0x1ul<<26)
#define EVENT_BIT27                     (0x1ul<<27)
#define EVENT_BIT28                     (0x1ul<<28)
#define EVENT_BIT29                     (0x1ul<<29)
#define EVENT_BIT30                     (0x1ul<<30)
#define EVENT_BIT31                     (0x1ul<<31)
/**
 * @}
 */

/**
 * @}
 */

/* 类型定义-------------------------------------------------------------------*/
/**
 * @defgroup sync_method_global_types sync method global types
 * @{
 */

/** 
  * @brief  信号量 type define
  */
typedef uint32_t sync_sem_t;

/** 
  * @brief  互斥锁 type define
  */
typedef uint8_t sync_mutex_t;

/** 
  * @brief  事件集 type define
  */
typedef uint32_t sync_event_t;

/**
 * @}
 */

/* 全局变量-------------------------------------------------------------------*/

/* 函数原型-------------------------------------------------------------------*/
/**
 * @addtogroup sync_method_global_functions
 * @{
 */

void sync_sem_init(sync_sem_t *_sem, uint32_t value);
void sync_sem_put(sync_sem_t *_sem);
uint8_t sync_sem_get(sync_sem_t *_sem);
uint32_t sync_sem_value(sync_sem_t *_sem);

void sync_mutex_init(sync_mutex_t *_mutex);
void sync_mutex_put(sync_mutex_t *_mutex);
uint8_t sync_mutex_get(sync_mutex_t *_mutex);

void sync_event_init(sync_event_t *_event);
void sync_event_put(sync_event_t *_event, uint32_t bits);
uint8_t sync_event_get(sync_event_t *_event, uint32_t bits, uint8_t eventFlg, uint8_t eventAct);

/**
 * @}
 */

/**
 * @}
 */

/**
 * @}
 */

#ifdef __cplusplus
}
#endif

#endif /* sync_method.h */
